<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<style>
	.red { 	background: #ef2b31;
		    width: 100px;
		    height: 40px;
		    line-height: 40px;
		    text-align: center;
		    color: #fff;
		    font-size: 16px;
		    border-radius: 5px;}
		    
	.shop_lis{ display:block;  overflow:hidden; margin-bottom:20px;}
	.shop_lis li{ width:23%; border:1px solid #c9c9c9; height:auto; overflow:hidden; float:left; margin-left:4px; margin-top:6px;}
	.shop_lis li p{ line-height:20px; margin-left:8px; color:#474747;}
	.shop_lis li span{ line-height:20px; margin-left:8px; color:#df5b5b;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=p4SAubK2v1COfHBrRDq77CYu"></script>
<script type="text/javascript">
	function m_submit(){
		window.saveOrEditForm.submit();
	}
	
	function m_back(){
		window.location.href = 'manage';
	}
	//地图所需变量
	//地图上得点
	var marker;
	//地图
	var map;
	//经纬度以及地址变量
	var lonel,latel,addrel;
	function initPosition(){
		var lon = $("*[name="+lonel+"]").val() || 116.400244;
		var lat = $("*[name="+latel+"]").val() || 39.92556;
		// 百度地图API功能
		if(!map){
			map = new BMap.Map("map");
		}else{
			map.clearOverlays();   
		}
		var point = new BMap.Point(lon,lat);
		map.centerAndZoom(point, 12);
		marker = new BMap.Marker(point);// 创建标注
		map.addOverlay(marker);             // 将标注添加到地图中
		marker.enableDragging();           // 不可拖拽
		$("#addDialog").panel("open");
	}
	function savePosition(){
		var p = marker.getPosition();       //获取marker的位置
		$("*[name="+lonel+"]").val(p.lng);
		$("*[name="+latel+"]").val(p.lat);
		$("#addDialog").panel("close");
	}
	
	//可守户型
	var id= '${model.id}';
	var apartmentlist = '${model.apartmentsList}';
	apartmentlist = apartmentlist?$.evalJSON(apartmentlist):[];
	function addApartment(){
		var area = $("#addForm").find('*[name="area"]').val();
		var apartmentLayout1 = $("#addForm").find('*[name="apartmentLayout1"]').val();
		var apartmentLayout2 = $("#addForm").find('*[name="apartmentLayout2"]').val();
		var apartmentLayout3 = $("#addForm").find('*[name="apartmentLayout3"]').val();
		var apartmentLayout4 = $("#addForm").find('*[name="apartmentLayout4"]').val();
		var url = $("#addForm").find('*[name="url2"]').val();
		var apartmentLayout = apartmentLayout1+apartmentLayout2+apartmentLayout3+apartmentLayout4;
		if(!$.trim(area)){
		 		$.messager.show({
						title:'YiXun助手',
						msg:'请输入面积！'
				});
				return false;
		}
		if(!$.trim(apartmentLayout)){
		 		$.messager.show({
						title:'YiXun助手',
						msg:'请选择户型！'
				});
				return false;
		}
		if(!$.trim(url)){
		 		$.messager.show({
						title:'YiXun助手',
						msg:'请上传图片！'
				});
				return false;
		}
		var apartment={
			id:'',
			premisesId:'',
			area:area,
			apartmentLayout:apartmentLayout,
			url:url
		}
		saveApartment(apartment);
	}
	//保存
	function saveApartment(apartment){
		if(id){
		}
		apartmentlist.push(apartment);
		$("#apartmentsList").val($.toJSON(apartmentlist));
		$("#addApartmentDialog").panel("close");
		renderApartment(apartment);
	}
	//渲染到页面
	function renderApartment(apartment){
		var html =   '<li id="'+apartment.id+'">'
		         +'<div><img src="'+apartment.url+'" width="100px" height="100px" alt=""></div>'
		         +'<p>'+apartment.apartmentLayout+'  '+apartment.area+'平</p>'
		         +'<span class="del">删除</span>'
		         +'<input type="hidden" name="apartments" value='+$.toJSON([apartment])+' class="ipt_226" />'
		         +'</li>'
		$(".shop_lis").append(html);
	}
	//渲染到页面
	function delApartment(index){
		var apartment = apartmentlist[index];
		if(apartment.id){
			//删除
				$.messager.confirm('确认!','你确定要删除此户型吗?',function(res){
					if(res){
						$.post("${ctx}/xf/apartmentlayoutdiagram/del",{'id':apartment.id},function(result){
							if (result.errorMsg){
								$.messager.show({
									title: '友情提示',
									msg: 'result.errorMsg'
								});
								m_datagrid.datagrid('reload');
							} else {
								$.messager.show({
									title: '友情提示',
									msg: '删除成功'
								});
								apartmentlist.splice(index,1);
								$(".shop_lis").find('li').eq(index).remove();
								$("#apartmentsList").val($.toJSON(apartmentlist));
							}
						},'json');
					}
			 });
		}else{
			apartmentlist.splice(index,1);
			$(".shop_lis").find('li').eq(index).remove();
			$("#apartmentsList").val($.toJSON(apartmentlist));
			$.messager.show({
									title: '友情提示',
									msg: '删除成功'
			});
		}
	}
	$(function(){
		$(".modify_property").on("click",function(){
			lonel=$(this).attr("lon");
			latel=$(this).attr("lat");
			addrel=$(this).attr("addr");
			initPosition();
		})
		$(".add_apartment").on("click",function(){
			$("#addForm").form("clear");
			$("#addForm").find("img").hide();
			$("#addApartmentDialog").panel("open");
		})
		$(".shop_lis").on("click","li .del",function(){
			var index = $(this).parent("li").index();
			delApartment(index);
		})
		
		for(var apartment in apartmentlist){
			renderApartment(apartmentlist[apartment]);
		}
	})
	
	
	<#if errorMsg?exists >alert('${errorMsg}');</#if>
</script>
</head>
<body style="height:3000px;">
  <form action="${ctx}/xf/premises/save_edit" method="post" class="loan_list_form" name="saveOrEditForm">
  <input type="hidden" name="id" value="<#if model?exists >${model.id}</#if>" />
  <div class="fm_sty" style="margin: 20px 0px 0px;">
	
			<div class="ipt_line">
				<span class="ipt_title" style="margin-bottom:10px;font-size: 20px;">基本信息</span>
				<hr/>
			</div>
			
	       	<div class="ipt_line">
				<span class="ipt_title">商圈</span>
				<input type="text" name="businessCirclesId" value="<#if model?exists >${model.businessCirclesId}</#if>" class="easyui-combobox" style="width:264px;height:39px;" data-options="valueField: 'id',textField: 'name',url: '${ctx}/xf/businesscircles/combo'"/>
			</div>
	       	
	       	<div class="ipt_line">
				<span class="ipt_title">楼盘名称</span>
				<input type="text" name="name" value="<#if model?exists >${model.name}</#if>" class="ipt_226" style="width:600px;"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">物业类型</span>
				<input type="text" id="estateType_id" name="estateType" style="height:39px;width:266px;" yixun_combobox="estate_type" value="<#if model?exists >${model.estateType}</#if>"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">建筑类别</span>
				<input type="text" id="buildingType_id" name="buildingType" style="height:39px;width:266px;" yixun_combobox="building_type" value="<#if model?exists >${model.buildingType}</#if>"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">装修状况</span>
				<input type="text" id="decorationType_id" name="decorationType" style="height:39px;width:266px;" yixun_combobox="decoration_type" value="<#if model?exists >${model.decorationType}</#if>"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">项目特色</span>
				<input type="text" name="feature" value="<#if model?exists >${model.feature}</#if>" class="ipt_226" style="width:600px;"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">容积率</span>
				<input type="text" name="plotRatio" value="<#if model?exists >${model.plotRatio}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">绿化率</span>
				<input type="text" name="greeningRate" value="<#if model?exists >${model.greeningRate}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">在售状态</span>
				<input type="text" id="saleStatus_id" name="saleStatus" style="height:39px;width:266px;" yixun_combobox="sale_status" value="<#if model?exists >${model.saleStatus}</#if>"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">开盘时间</span>
				<input type="text" name="openingTime" value="<#if model?exists >${model.openingTime?string("yyyyMMdd HH:mm:ss")}</#if>" class="easyui-datebox" panelWidth="255" style="height:39px;"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">入住时间</span>
				<input type="text" name="checkInTime" value="<#if model?exists >${model.checkInTime?string("yyyyMMdd HH:mm:ss")}</#if>" class="easyui-datebox" panelWidth="255" style="height:39px;"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">物业费</span>
				<input type="text" name="propertyCharges" value="<#if model?exists >${model.propertyCharges}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">物业公司</span>
				<input type="text" name="propertyCompany" value="<#if model?exists >${model.propertyCompany}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">开发商</span>
				<input type="text" name="buildingCompany" value="<#if model?exists >${model.buildingCompany}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">产权年限</span>
				<input type="text" name="rightYears" value="<#if model?exists >${model.rightYears}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">均价</span>
				<input type="text" name="averagePrice" value="<#if model?exists >${model.averagePrice}</#if>" class="ipt_226" />
			</div>
<!--
	       	<div class="ipt_line">
				<span class="ipt_title">物业地址 <button type="button" id="modify_property" class="red_100">修改经纬度</button></span>
			</div>
	       	<div class="ipt_line">
				<span class="ipt_title">物业地址经度</span>
				<input type="text" name="propertyLongitude" value="<#if model?exists >${model.propertyLongitude}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">物业地址纬度</span>
				<input type="text" name="propertyLatitude" value="<#if model?exists >${model.propertyLatitude}</#if>" class="ipt_226" />
			</div>
-->
			<div class="ipt_line">
				<span class="ipt_title">物业地址</span>
				<input type="text" name="propertyAddr" value="<#if model?exists >${model.propertyAddr}</#if>" class="ipt_226" /><button type="button" addr="propertyAddr" lon="propertyLongitude" lat="propertyLatitude" class="red modify_property">修改经纬度</button>
			</div>
			 	<div class="ipt_line">
				<span class="ipt_title">物业地址经度</span>
				<input type="text" name="propertyLongitude"  value="<#if model?exists >${model.propertyLongitude}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">物业地址纬度</span>
				<input type="text" name="propertyLatitude"  value="<#if model?exists >${model.propertyLatitude}</#if>" class="ipt_226" />
			</div>
  

	       	<div class="ipt_line">
				<span class="ipt_title">售楼部地址</span>
				<input type="text" name="saleAddr" value="<#if model?exists >${model.saleAddr}</#if>" class="ipt_226" /><button type="button" addr="saleAddr" lon="saleLongitude" lat="saleLatitude" class="red modify_property">修改经纬度</button>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">售楼部地址经度</span>
				<input type="text" name="saleLongitude" value="<#if model?exists >${model.saleLongitude}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">售楼部地址纬度</span>
				<input type="text" name="saleLatitude"   value="<#if model?exists >${model.saleLatitude}</#if>" class="ipt_226" />
			</div>
			<div class="ipt_line">
				<span class="ipt_title" style="margin-bottom:10px;font-size: 20px;">分销信息</span>
				<hr/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">购房优惠</span>
				<input type="text" name="discount" value="<#if model?exists >${model.discount}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">佣金</span>
				<input type="text" name="commission" value="<#if model?exists >${model.commission}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">奖励</span>
				<input type="text" name="reward" value="<#if model?exists >${model.reward}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">带看保护期</span>
				<input type="text" name="saveDays" value="<#if model?exists >${model.saveDays}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">项目经理</span>
				<input type="text" name="manager" value="<#if model?exists >${model.manager}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">联系方式</span>
				<input type="text" name="mobile" value="<#if model?exists >${model.mobile}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">合作有效期</span>
				<input type="text" name="cooperationBeginTime" value="<#if model?exists >${model.cooperationBeginTime?string("yyyyMMdd HH:mm:ss")}</#if>" class="easyui-datebox" panelWidth="255" style="height:39px;"/>
				<input type="text" name="cooperationEndTime" value="<#if model?exists >${model.cooperationEndTime?string("yyyyMMdd HH:mm:ss")}</#if>" class="easyui-datebox" panelWidth="255" style="height:39px;"/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">合作规则</span>
				<input type="text" name="cooperationRule" value="<#if model?exists >${model.cooperationRule}</#if>" class="ipt_226" />
			</div>

			<div class="ipt_line">
				<span class="ipt_title" style="margin-bottom:10px;font-size: 20px;">其他信息</span>
				<hr/>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title" style="position:absolute;">项目简介</span>
				<textarea name="introduction" id="introduction" style="height: 325px;"><#if model?exists >${model.introduction}</#if></textarea>  
				<script type="text/javascript"> 
					var editorFinanceCycle = new UE.ui.Editor({
					}); 
					editorFinanceCycle.render("introduction"); 
				</script> 
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">楼盘卖点</span>
				<input type="text" name="selling" value="<#if model?exists >${model.selling}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">目标客户</span>
				<input type="text" name="customer" value="<#if model?exists >${model.customer}</#if>" class="ipt_226" />
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">拓客技巧</span>
				<input type="text" name="saleSkill" value="<#if model?exists >${model.saleSkill}</#if>" class="ipt_226" />
			</div>
			<div class="ipt_line">
				<span class="ipt_title">可售户型</span>
				<input type="hidden" name="apartmentsList" id="apartmentsList" value="<#if model?exists >${model.apartmentsList}</#if>" class="ipt_226" />
				<button type="button"  class="red add_apartment">添加户型图</button>
			</div>
			<div class="ipt_line">
				<ul class="shop_lis">
				<!--
		        	<li>
		            	<div><img src="${img}/shop_lis_img_1.png" width="100px" height="100px" alt=""></div>
		                <p>贵州茅台53度酱香型...</p>
		                <span>会员价: ￥180</span>
		            </li>
		            <li>
		            	<div><img src="${img}/shop_lis_img_1.png" width="100px" height="100px" alt=""></div>
		                <p>贵州茅台53度酱香型...</p>
		                <span>会员价: ￥180</span>
		            </li>
		            <li>
		            	<div><img src="${img}/shop_lis_img_1.png" width="100px" height="100px" alt=""></div>
		                <p>贵州茅台53度酱香型...</p>
		                <span>会员价: ￥180</span>
		            </li>
		            <li>
		            	<div><img src="${img}/shop_lis_img_1.png" width="100px" height="100px" alt=""></div>
		                <p>贵州茅台53度酱香型...</p>
		                <span>会员价: ￥180</span>
		            </li>-->
		          </ul>
			</div>
	       	<div class="ipt_line">
				<span class="ipt_title">封面图片地址</span>
				<input type="file" id="file1" name="file" onchange="uploadImg(this);" />
				<input type="hidden" name="url" value="<#if model?exists >${model.url}</#if>" class="ipt_226" />
				<#if (model?? && model.bannerImage?? &&  model.bannerImage!="")>
		 			<img  showbig src="${model.url}" style="width:25px;height:25px;" />
		 		<#else>
		 			<img showbig style="width:25px;height:25px;display:none" />
				</#if>
			</div>

	       	<div class="ipt_line">
				<span class="ipt_title">楼盘状态</span>
				<input type="text" id="premisesStatus_id" name="premisesStatus" style="height:39px;width:266px;" yixun_combobox="premises_status" value="<#if model?exists >${model.premisesStatus}</#if>"/>
			</div>

      <div class="ipt_line_long">
            <button class="red_100" onclick="javascript:m_submit();return false;">保存</button>
            <button class="red_100" onclick="javascript:m_back();return false;" style="background-color:#74D86A">返回</button>
      </div>
	</div>
	</form>
	<div id="addDialog" title="位置获取" class="easyui-dialog dialog table"
		data-options="width: 650,height:600, closed: true, modal : true, buttons: [{ id: 'saveBtn', text: '保存', iconCls: 'icon-save',handler:savePosition} ]">
       <div id="mapDiv" style="width: 100%;height: 100%;"><div id="map" style="width: 100%;height: 100%;overflow: hidden;margin:0;"></div></div>
    </div>
	<div id="addApartmentDialog" title="添加可售户型" class="easyui-dialog dialog table"
		data-options="width: 450,height:300, closed: true, modal : true, buttons: [{ id: 'addApartment', text: '保存', iconCls: 'icon-save',handler:addApartment} ]">
    	<form id="addForm" action="#" method="post" autocomplete="off">
    	<div class="ipt_line">
			<span class="ipt_title">面积：</span>
			<div><input type="text" class="text" name="area"/>平</div>
		</div>
		<div class="ipt_line">
			<span class="ipt_title">户型：</span>
			<div>
				<select class="easyui-combobox" name="apartmentLayout1" >
					<option>1室</option>
					<option>2室</option>
					<option>3室</option>
					<option>4室</option>
					<option>5室</option>
				</select>
				<select class="easyui-combobox" name="apartmentLayout2" >
					<option>1厅</option>
					<option>2厅</option>
					<option>3厅</option>
					<option>4厅</option>
					<option>5厅</option>
					<option>6厅</option>
					<option>7厅</option>
					<option>8厅</option>
				</select>
				<select class="easyui-combobox" name="apartmentLayout3" >
					<option>1卫</option>
					<option>2卫</option>
					<option>3卫</option>
					<option>4卫</option>
					<option>5卫</option>
					<option>6卫</option>
					<option>7卫</option>
					<option>8卫</option>
				</select>
				<select class="easyui-combobox" name="apartmentLayout4" data-options="width:100">
					<option>1阳台</option>
					<option>2阳台</option>
					<option>3阳台</option>
					<option>4阳台</option>
					<option>5阳台</option>
					<option>6阳台</option>
				</select>
			</div>
		</div>
		<div class="ipt_line">
			<span class="ipt_title">上传图片：</span>
			<div>
				<input type="file" id="file2" name="file" onchange="uploadImg(this);" />
				<input type="hidden" name="url2" value="<#if model?exists >${model.url}</#if>" class="ipt_226" />
		 		<img showbig style="width:25px;height:25px;display:none" />
			</div>
		</div>
		</form>
    </div>
</body>
</html>
